home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / sftwist.lha / SFox.c < prev    next >
C/C++ Source or Header  |  1993-07-21  |  9KB  |  348 lines

  1. ;/*  SFTWIST -- C demo by SilverFox
  2. SC DATA=NEAR COMNEST NMINC NOSTKCHK OPTIMIZE OPTTIME SFox.c
  3. ;SC DATA=NEAR COMNEST NMINC NOSTKCHK DEBUG=FULL SFox.c
  4. quit
  5. */
  6.  
  7. /*
  8.  *  This code is written by Adisak Pochanayon of SilverFox
  9.  *  SoftWare.  It will run on any Amiga with at least 1 MB
  10.  *  of memory although a 68020+ processor is highly
  11.  *  recommended.
  12.  *
  13.  *  Freely Distributable as the entire archive only!!!
  14.  *
  15.  *  Copyright 1993 Adisak Pochanayon.
  16.  */
  17.  
  18. #include <proto/exec.h>
  19. #include <proto/intuition.h>
  20. #include <proto/graphics.h>
  21. #include <proto/layers.h>
  22.  
  23. #include <exec/memory.h>
  24. #include <exec/execbase.h>
  25.  
  26. #include <stdlib.h>
  27. #include <string.h>
  28.  
  29. /*** MED MUSIC ***/
  30. //#include <med/modplayer/modplayer.h>
  31. #include "modplayer.h"
  32. #include "iff.h"
  33.  
  34. extern struct MMD0 far MEDSONG;
  35.  
  36. void __chkabort(void) {}    /* Disable SAS CTRL-C handling */
  37.  
  38. /***** Declarations for CBACK *****/
  39. long __BackGroundIO = 0;
  40. long __stack = 10000;
  41. char *__procname = "TWIST by SilverFox";
  42. long __priority = 8;
  43.  
  44. /*****  Libraries  *****/
  45. struct IntuitionBase *IntuitionBase=NULL;
  46. struct GfxBase       *GfxBase=NULL;
  47. struct Library       *LayersBase=NULL;
  48. struct Library       *IFFBase=NULL;
  49.  
  50. extern unsigned char far BM0[32000];
  51. extern unsigned char SILVERFOX[1];
  52.  
  53. /****
  54. struct BitMap
  55.   { UWORD BytesPerRow, Rows;
  56.     UBYTE Flags, Depth;
  57.     UWORD   pad;
  58.     PLANEPTR Planes[8]; }
  59. ****/
  60. struct BitMap BMap =
  61. { 40, 200, 0, 4, 0, &BM0[16000], &BM0[8000], &BM0[24000],
  62.   &BM0[0], NULL, NULL, NULL, NULL };
  63.  
  64. struct BitMap LineMap =
  65. { 40, 200, 0, 1, 0, &BM0[24000], NULL, NULL, NULL, NULL, NULL, NULL, NULL };
  66.  
  67. struct BitMap LoadMap =
  68. { 40, 200, 0, 1, 0, &BM0[0], NULL, NULL, NULL, NULL, NULL, NULL, NULL };
  69.  
  70. struct Layer_Info *LI=NULL;
  71. struct Layer *layer=NULL;
  72.  
  73. struct NewScreen NewScreenStructure = {
  74.     0,0,    /* screen XY origin relative to View */
  75.     320,200,    /* screen width and height */
  76.     4,    /* screen depth (number of bitplanes) */
  77.     0,1,    /* detail and block pens */
  78.     SPRITES,    /* display modes for this screen */
  79.     SCREENQUIET|CUSTOMSCREEN|CUSTOMBITMAP,    /* screen type */
  80.     NULL,    /* pointer to default screen font */
  81.     NULL,    /* screen title */
  82.     NULL,    /* first in list of custom screen gadgets */
  83.     &BMap    /* pointer to custom BitMap structure */
  84. };
  85.  
  86. struct Screen *MyScreen=NULL;
  87.  
  88. struct NewWindow NewWindowStructure1 = {
  89.     0,0,    /* window XY origin relative to TopLeft of screen */
  90.     320,200,    /* window width and height */
  91.     0,1,    /* detail and block pens */
  92.     VANILLAKEY,    /* IDCMP flags */
  93.     /* other window flags */
  94.     SIMPLE_REFRESH|BORDERLESS|RMBTRAP|NOCAREREFRESH|BACKDROP|ACTIVATE,
  95.     NULL,    /* first gadget in gadget list */
  96.     NULL,    /* custom CHECKMARK imagery */
  97.     NULL,    /* window title */
  98.     NULL,    /* custom screen pointer */
  99.     NULL,    /* custom bitmap */
  100.     1,1,    /* minimum width and height */
  101.     (UWORD)-1,(UWORD)-1,    /* maximum width and height */
  102.     CUSTOMSCREEN    /* destination screen type */
  103. };
  104.  
  105. struct Window *MyWindow=NULL;
  106.  
  107. extern ULONG far NOMOUSE[];
  108.  
  109. UBYTE *MASSIVE_STORAGE[80];
  110. UBYTE DOLINE[320];
  111. UBYTE direction[200];
  112.  
  113. struct RastPort *rp1;
  114.  
  115. char *funfile=NULL;
  116.  
  117. WORD SquiggleArray[200+320+320];
  118.  
  119. WORD ColorPalette[16] = { 0x000,0x558,0x88B,0xFFF };
  120.  
  121. WORD SUPER[48]=
  122. { 0x00F,0x10E,0X20D,0X30C,0X40B,0X50A,0X609,0X708,
  123.   0X807,0X906,0XA05,0XB04,0XC03,0XD02,0XE01,0XF00,
  124.   0XF00,0XE10,0XD20,0XC30,0XB40,0XA50,0X960,0X870,
  125.   0X780,0X690,0X5A0,0X4B0,0X3C0,0X2D0,0x1E0,0x0F0,
  126.   0X0F0,0X0E1,0X0D2,0X0C3,0X0B4,0X0A5,0X096,0X087,
  127.   0X078,0X069,0X05A,0X04B,0X03C,0X02D,0X01E,0X00F };
  128.  
  129. VOID __regargs GoLine(WORD line_d0);
  130. VOID __regargs UnPackSLZ(UBYTE *from_a0, UBYTE *to_a1);
  131. VOID __regargs BresenFold(UBYTE *from_a0, UBYTE *to_a1);
  132. VOID __regargs ReverseIt(UBYTE *from_a0, UBYTE *to_a1);
  133.  
  134. VOID __regargs StarOffsets(ULONG mod_d0);
  135. VOID ComputeStarField(void);
  136. VOID DisplayStarField(void);
  137. extern PLANEPTR far Plane1ptr;
  138. extern PLANEPTR far Plane2ptr;
  139.  
  140. /***************  Beginning of code  ***************/
  141.  
  142. VOID CleanUp(void)
  143. {
  144.   WORD loop;
  145.  
  146.   if (MyWindow!=NULL)
  147.     CloseWindow(MyWindow);
  148.   if (MyScreen!=NULL)
  149.     CloseScreen(MyScreen);
  150.   if (layer)
  151.     DeleteLayer((long)LI,layer);
  152.   if (LI)
  153.     DisposeLayerInfo(LI);
  154.   if (IFFBase!=NULL)
  155.     CloseLibrary(IFFBase);
  156.   if (LayersBase!=NULL)
  157.     CloseLibrary(LayersBase);
  158.   if (IntuitionBase!=NULL)
  159.     CloseLibrary((struct Library *)IntuitionBase);
  160.   if (GfxBase!=NULL)
  161.     CloseLibrary((struct Library *)GfxBase);
  162.   for(loop=0; loop!=80; loop++)
  163.     {
  164.       if (MASSIVE_STORAGE[loop])
  165.         FreeMem(MASSIVE_STORAGE[loop],8000);
  166.     }
  167.   exit(0);
  168. }
  169.  
  170. VOID InitStuff(void)
  171. {
  172.   WORD loop;
  173.   IFFL_HANDLE iff;
  174.  
  175. /**** Get Memory Chunk ****/
  176.   for(loop=0; loop!=200; loop++)
  177.     direction[loop]=0;
  178.   for(loop=0; loop!=80; loop++)
  179.     MASSIVE_STORAGE[loop]=NULL;
  180.   for(loop=0; loop!=80; loop++)
  181.     {
  182.       if ((MASSIVE_STORAGE[loop]=AllocMem(8000,MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  183.         CleanUp();
  184.     }
  185.  
  186. /**** Open Libraries ****/
  187.   if (
  188.     ((GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0))==NULL) ||
  189.     ((IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0))==NULL) ||
  190.     ((LayersBase=OpenLibrary("layers.library",0))==NULL)  ||
  191.     ((IFFBase = OpenLibrary(IFFNAME, IFFVERSION))==NULL)
  192.      )
  193.     { CleanUp(); }
  194.  
  195. /**** Funky Self Layers Stuff ****/
  196.   if ((LI=NewLayerInfo())==NULL)
  197.     CleanUp();
  198.   if ((layer=CreateUpfrontLayer(LI,&LineMap,0,0,319,199,LAYERSIMPLE,NULL))==NULL)
  199.     CleanUp();
  200.   rp1=layer->rp; SetDrMd(rp1,COMPLEMENT); SetAPen(rp1,1);
  201.  
  202. /***** SCREEN OPEN *****/
  203.   if ((MyScreen=(struct Screen *) OpenScreen(&NewScreenStructure))==NULL)
  204.     CleanUp();
  205.   LoadRGB4(&MyScreen->ViewPort,ColorPalette,16);
  206.  
  207. /***** WINDOW OPEN *****/
  208.  
  209.   NewWindowStructure1.Screen = MyScreen;
  210.   if ((MyWindow=(struct Window *) OpenWindow(&NewWindowStructure1))==NULL)
  211.     CleanUp();
  212.  
  213.   SetPointer(MyWindow,(short*)&NOMOUSE[0],1,16,0,0);
  214.   SetRast(MyWindow->RPort,0);
  215.  
  216. /*** Show the SilverFox Logo -- BEGIN DEMO  ***/
  217.   Plane1ptr=&BM0[16000];
  218.   Plane2ptr=&BM0[8000];
  219.   StarOffsets(40);
  220.  
  221.   WaitTOF(); WaitTOF();
  222.   loop=1;
  223.   if(funfile)
  224.     {
  225.       if(iff = IFFL_OpenIFF(funfile, IFFL_MODE_READ) )
  226.         {
  227.           if(IFFL_DecodePic(iff,&LoadMap))
  228.             {
  229.               loop=0;
  230.             }
  231.         }
  232.     }
  233.   if(loop)
  234.     {
  235.       UnPackSLZ(SILVERFOX,BM0);
  236.     }
  237. }
  238.  
  239. VOID MakeSquiggle(void)
  240. {
  241.   WORD loop;
  242.   for(loop=640; loop!=(320+320+200); loop++)
  243.     {
  244.       SquiggleArray[loop]=79;      
  245.     }
  246.   for(loop=0; loop!=80; loop++)
  247.     {
  248.       SquiggleArray[loop]    =79-loop;
  249.       SquiggleArray[loop+80] =loop;
  250.       SquiggleArray[loop+160]=79-loop;
  251.       SquiggleArray[loop+240]=loop;
  252.       SquiggleArray[loop+320]=79-loop;
  253.       SquiggleArray[loop+400]=loop;
  254.       SquiggleArray[loop+480]=79-loop;
  255.       SquiggleArray[loop+560]=loop;
  256.     }
  257. }
  258.  
  259. LONG main( int argc, char **argv )
  260. {
  261.   WORD Activated,loop2,count,thecolor1=0,thecolor2=24;
  262.   UBYTE *to,*mydir;
  263.   WORD *Squigs;
  264.  
  265.   WORD dirx1=+4,diry1=-3;
  266.   WORD dirx2=+3,diry2=-2;
  267.   WORD currentx1=160, currenty1=50;
  268.   WORD currentx2=160, currenty2=50;
  269.   WORD history=0;
  270.   WORD hy1[8]={300,300,300,300,300,300,300,300};
  271.   WORD hy2[8]={300,300,300,300,300,300,300,300};
  272.   WORD hx1[8]={400,400,400,400,400,400,400,400};
  273.   WORD hx2[8]={400,400,400,400,400,400,400,400};
  274.  
  275.   WORD FASTCPU;
  276.  
  277.   FASTCPU = (*((struct ExecBase **)(4L)))->AttnFlags;
  278.   if(FASTCPU&AFF_68030) FASTCPU=TRUE; else FASTCPU=FALSE;
  279.   if (argc==2) funfile=argv[1];
  280.  
  281.   InitStuff();
  282.   MakeSquiggle();
  283.   RelocModule(&MEDSONG);
  284.   InitPlayer();
  285.   PlayModule(&MEDSONG);
  286.   count=640; Activated=FALSE; loop2=0;
  287.   while(GetMsg(MyWindow->UserPort)==0)
  288.     {
  289.       if(Activated)
  290.         {
  291.           to=&BM0[0];
  292.           Squigs=&SquiggleArray[count];
  293.           if((--count)==0)
  294.             {
  295.               count+=320;
  296.             }
  297.           mydir=&direction[0];
  298.           for(loop2=0; loop2<(200*40); loop2+=40)
  299.             {
  300.               if(*mydir)
  301.                 ReverseIt(&MASSIVE_STORAGE[*Squigs][loop2],to);
  302.               else
  303.                 BresenFold(&MASSIVE_STORAGE[*Squigs][loop2],to);
  304.               if((Squigs[0]==0)&&(Squigs[1]==0))
  305.                 *mydir=*mydir^1;
  306.               mydir++;
  307.               to += 40;
  308.               Squigs+=1;
  309.             }
  310.           ComputeStarField();
  311.           if (FASTCPU) WaitTOF();
  312.           DisplayStarField();
  313.         }
  314.       else
  315.         {
  316.           GoLine(loop2);
  317.           if((loop2+=40)==(200*40)) Activated=TRUE;
  318.         }
  319.       Move(rp1,hx1[history],hy1[history]);
  320.       Draw(rp1,hx2[history],hy2[history]);
  321.       hx1[history]=(currentx1+=dirx1);
  322.       hy1[history]=(currenty1+=diry1);
  323.       hx2[history]=(currentx2+=dirx2);
  324.       hy2[history]=(currenty2+=diry2);
  325.       if((currentx1<10)||(currentx1>310)) dirx1=-dirx1;
  326.       if((currentx2<10)||(currentx2>310)) dirx2=-dirx2;
  327.       if((currenty1<10)||(currenty1>190)) diry1=-diry1;
  328.       if((currenty2<10)||(currenty2>190)) diry2=-diry2;
  329.       Move(rp1,currentx1,currenty1);
  330.       Draw(rp1,currentx2,currenty2);
  331.       history++; history&=7;
  332.       thecolor1++; if (thecolor1==48) thecolor1=0;
  333.       if(((thecolor1)&3)==0)
  334.         {
  335.           thecolor2++; if (thecolor2==48) thecolor2=0;
  336.         }
  337.       ColorPalette[4]=ColorPalette[5]=ColorPalette[6]=
  338.         ColorPalette[7]=SUPER[thecolor1];
  339.       ColorPalette[8]=ColorPalette[9]=ColorPalette[10]=
  340.         ColorPalette[11]=ColorPalette[12]=ColorPalette[13]=
  341.         ColorPalette[14]=ColorPalette[15]=SUPER[thecolor2];
  342.       LoadRGB4(&MyScreen->ViewPort,ColorPalette,16);
  343.     }
  344.   RemPlayer();
  345.   CleanUp();
  346. }
  347.  
  348.